import("/lay/lib/jquery-3.4.1/jquery-3.4.1.min.js")

//ajax判断教室是否存在
function exitClassRoom() {
    let classRoomName = $("#classRoomName").val();
    $.get("class-room/existClassRoom", {roomName: classRoomName}, function (result) {
        if (result.success == false) {
            $("#redmsg").remove();
            $("#message").append("<span id='redmsg' style='color: red'>" + '*教室不存在*' + "</span>");
            $("#classRoomName").val("");
        } else {
            $("#redmsg").remove();
        }
    })

}

//ajax判断班级是否存在
function exitClass() {
    let className = $("#className").val();
    $.get("_class/exitClass", {className: className}, function (result) {
        if (result.success == false) {
            $("#redmsg1").remove();
            $("#message1").append("<span id='redmsg1' style='color: red'>" + '*班级不存在*' + "</span>");
            $("#className").val("");
        } else {
            $("#redmsg1").remove();
        }
    })

}

//可能存在用户名相同的用户，（目前只是判断用户是否存在），所以修改这方面可能存在问题，到时候在这里判断（暂时埋坑）
function checkUserName() {
    let studentName = $("#studentName").val();
    $.get("student/existStudent", {studentName: studentName}, function (result) {

        if (!result) {
            $("#userMsg").remove();
            $("#stu").append("<span id='userMsg' style='color: red'>" + '*用户不存在*' + "</span>");
            $("#studentName").val("");
        } else {
            $("#userMsg").remove();
        }
    });
}

/**
 * 检查，地面卫生的方法
 */
function checkFloor() {

    let floorHealth = $("#floorHealth").val();

    if (parseInt(floorHealth) < 0 || parseInt(floorHealth.substring(0, 1)) == 0 || parseInt(floorHealth) > 8) {
        $("#checkfloor").remove();
        $("#floor").append("<span id='checkfloor' style='color: red' class='iconfont icon-jinggao'>" + '*地面卫生最高8分*' + "</span>");
        $("#floorHealth").val(0);
    } else {
        $("#checkfloor").remove();
    }
    score();
}

/**
 * 检查，桌面卫生的方法
 */
function checkDesktop() {

    let desktopHealth = $("#desktopHealth").val();

    if (parseInt(desktopHealth) < 0 || parseInt(desktopHealth.substring(0, 1)) == 0 || parseInt(desktopHealth) > 6) {
        $("#checkDesktopHealth").remove();
        $("#desktop").append("<span id='checkDesktopHealth' style='color: red' class='iconfont icon-jinggao'>" + '*桌面卫生最高6分*' + "</span>");
        $("#floorHealth").val(0);
    } else {
        $("#checkDesktopHealth").remove();
    }
    score();
}

/**
 * 检查区域卫生的方法
 */
function checkAreaHealth() {

    let areaHealth = $("#areaHealth").val();

    if (parseInt(areaHealth) < 0 || parseInt(areaHealth.substring(0, 1)) == 0 || parseInt(areaHealth) > 3) {
        $("#checkAreaHealth").remove();
        $("#area").append("<span id='checkAreaHealth' style='color: red' class='iconfont icon-jinggao'>" + '*区域卫生最高3分*' + "</span>");
        $("#areaHealth").val(0);
    } else {
        $("#checkAreaHealth").remove();
    }
    score();
}

/**
 * 柜子卫生
 */
function checkCabinetHealth() {

    let cabinetHealth = $("#cabinetHealth").val();

    if (parseInt(cabinetHealth) < 0 || parseInt(cabinetHealth.substring(0, 1)) == 0 || parseInt(cabinetHealth) > 3) {
        $("#checkCabinetHealth").remove();
        $("#cabinet").append("<span id='checkCabinetHealth' style='color: red' class='iconfont icon-jinggao'>" + '*柜子卫生最高3分*' + "</span>");
        $("#cabinetHealth").val(0);
    } else {
        $("#checkCabinetHealth").remove();
    }
    score();
}
let isred = $("#isRed");
/**
 * 计算总分
 */
function score() {
    let floorHealth = $("#floorHealth").val();
    let desktopHealth = $("#desktopHealth").val();
    let areaHealth = $("#areaHealth").val();
    let cabinetHealth = $("#cabinetHealth").val();
    let sum = parseInt(floorHealth) + parseInt(desktopHealth) + parseInt(areaHealth) + parseInt(cabinetHealth)
    $("#score").val(sum);
    addIredStyle(sum);
}
$(function () {
    let sum = parseInt($("#floorHealth").val()) + parseInt($("#desktopHealth").val()) + parseInt($("#areaHealth").val()) + parseInt($("#cabinetHealth").val());
    addIredStyle(sum);
})
function addIredStyle(sum) {
    if (sum > 16) {
        $("#red").remove();
        isred.append(" <div  id='red' style='padding-top: 0.7%;color: #61bc56' class='iconfont icon-jinggao'>未标红</div>");
    }else {
        $("#red").remove();
        isred.append(" <div id='red' style='padding-top: 0.7%;color: red' class='iconfont icon-jinggao'>标红</div>");
    }
}